import bpy

class Vertex:
    def __init__(self, x, y, z, nx, ny, nz, tu, tv):
        self.x = x
        self.y = y
        self.z = z
        self.nx = nx
        self.ny = ny
        self.nz = nz
        self.tu = tu
        self.tv = tv
        
    def equals (self, o):
        return self.x == o.x and self.y == o.y and self.z == o.z and self.nx == o.nx and self.ny == o.ny and self.nz == o.nz and self.tu == o.tu and self.tv == o.tv
    
    
    
class VertexList:
    def __init__(self):
        self.vertices = []
        
    def add_data (self, x, y, z, nx, ny, nz, tu, tv):
        return self.add (Vertex (x, y, z, nx, ny, nz, tu, tv))
        
    def add(self, vertex):
        i=0
        for v in self.vertices:
            if v.equals (vertex):
                return i
            i+=1
            
        self.vertices.append(vertex)
        return i
    
    def size(self):
        return len(self.vertices)

    def get(self, i):
        return self.vertices[i]    
    
    def data(self):
        return self.vertices

class MeshStruct:
    
    def __init__(self, mesh = None):
        self.vertices = VertexList()
        if mesh:
            self.init_mesh_data (mesh)
            
            

    def init_mesh_data (self, mesh):
        for f in mesh.faces:
            idx_tmpl = [[0, 1, 2], [0, 2, 3]]
            if f.vertices [3] != 0:
                num = 2
            else:
                num = 1
                
            for i in range(num):
                tmpl = idx_tmpl[i]
                
                for p in range (3):
                    v = mesh.vertices [f.vertices [tmpl[0]]]
                    
                    co = v.co
                    no = f.normal
                    if f.use_smooth:
                        no = v.normal
                        
                    
                    self.vertices.add_data (co.x, co.y, co.z, no.x, no.y, no.z,   0, 0)
            
        for v in self.vertices.data():
            print ("   %f %f %f    %f %f %f" % (v.x, v.y, v.z, v.nx, v.ny, v.nz))

def export_mesh (mesh):
    ms = MeshStruct ()
    ms.init_mesh_data (mesh)            

print ("Start:")
# print all objects
for obj in bpy.data.objects:
    if obj.select:
        if isinstance (obj.data, bpy.types.Mesh):
            export_mesh (obj.data)
            


print ("Ende\n")